package pt.isel.lercm.projectmanager.managedController.resume;

import java.io.Serializable;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import pt.isel.lercm.projectmanager.auxobjects.Mode;
import pt.isel.lercm.projectmanager.spring.commons.GenericManagedBeanResume;
import pt.isel.lercm.projectmanager.spring.model.EmailTemplate;
import pt.isel.lercm.projectmanager.spring.service.IEmailTemplateService;


@ManagedBean(name = "emailTemplateResumeBean")
@ViewScoped
public class EmailTemplateResume extends GenericManagedBeanResume<EmailTemplate> implements Serializable{

	private static final long serialVersionUID = -9059615526243314976L;

	private List<EmailTemplate> templates;
	
	@ManagedProperty(value="#{EmailTemplateService}")
	IEmailTemplateService emailTemplateService;
	
	
	@Override
	public void init() {
		if (templates == null){
			templates = emailTemplateService.getAll();
		}
	}
	
	@Override
	public void visualizar(EmailTemplate object) {
		redirectToPage("/app/crud/emailTemplateCrud.xhtml?id="+ object.getId() +"&mode=" + Mode.LEITURA.mode,false);
	}

	@Override
	public void apagar(EmailTemplate object) {
		emailTemplateService.delete(object);
		
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "O email template foi apagado com sucesso!", ""));
		
	}

	@Override
	public void novo() {
		redirectToPage("/app/crud/emailTemplateCrud.xhtml?mode=" + Mode.NOVO.mode,false);
	}

	

	public List<EmailTemplate> getTemplates() {
		return templates;
	}

	public void setTemplates(List<EmailTemplate> templates) {
		this.templates = templates;
	}

	public IEmailTemplateService getEmailTemplateService() {
		return emailTemplateService;
	}

	public void setEmailTemplateService(IEmailTemplateService emailTemplateService) {
		this.emailTemplateService = emailTemplateService;
	}

}
